<!DOCTYPE html>
<!-- saved from url=(0046)https://www.cnblogs.com/a00ium/p/14128974.html -->
<html lang="zh-cn" style="--olcb-folder-code-block-max-height: 80vh; --cnb-code-bg: rgb(245, 245, 245); --cnb-code-font-size: 12px; --cnb-code-color: rgb(68, 68, 68);"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="referrer" content="never">
    
    <meta name="description" content="协议缓冲区（Protobuf）是Google开发的与语言无关的数据序列化格式。Protobuf之所以出色，原因如下： 数据量低：&amp;#160;Protobuf使用二进制格式，该格式比JSON等其他格式更紧凑。 持久性：&amp;#160;Protobuf序列化是向后兼容的。这意味着即使接口在此期间发生了更改，">
    <meta property="og:description" content="协议缓冲区（Protobuf）是Google开发的与语言无关的数据序列化格式。Protobuf之所以出色，原因如下： 数据量低：&amp;#160;Protobuf使用二进制格式，该格式比JSON等其他格式更紧凑。 持久性：&amp;#160;Protobuf序列化是向后兼容的。这意味着即使接口在此期间发生了更改，">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园</title>
    <link rel="canonical" href="https://www.cnblogs.com/a00ium/p/14128974.html">
    <link rel="shortcut icon" id="favicon" href="https://assets.cnblogs.com/favicon.svg?v=2" type="image/svg+xml">
    
    <style>#home :not(.cnblogs_code):not(.cnblogs_Highlighter)>pre:not([highlighted]):not([class*="brush:"]) code:not(.hljs), :not(.cnblogs_code):not(.cnblogs_Highlighter)>pre:not([highlighted]):not([class*="brush:"]) code:not(.hljs) {background: rgb(245, 245, 245);
        padding: 12px;
        border: 0.8px solid rgb(204, 204, 204);
        border-radius: 3px;
        border-color: transparent;
        color: rgb(68, 68, 68);
        font-family: "Courier New", sans-serif;
        font-size: 12px</style><link rel="stylesheet" href="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/blog-common.min.css">
    

    <link id="MainCss" rel="stylesheet" href="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/bundle-bluesky.min.css">
        <link id="highlighter-theme-cnblogs" type="text/css" rel="stylesheet" href="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/cnblogs.css">
    
    
    <link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/bundle-bluesky-mobile.min.css">
    
    <link type="application/rss+xml" rel="alternate" href="https://www.cnblogs.com/a00ium/rss">
    <link type="application/rsd+xml" rel="EditURI" href="https://www.cnblogs.com/a00ium/rsd.xml">
    <link type="application/wlwmanifest+xml" rel="wlwmanifest" href="https://www.cnblogs.com/a00ium/wlwmanifest.xml">
    <script>
        var currentBlogId = 233489;
        var currentBlogApp = 'a00ium';
        var isLogined = false;
        var isBlogOwner = false;
        var skinName = 'BlueSky';
        var visitorUserId = '';
        var hasCustomScript = false;
        window.cb_enable_mathjax = false;
        window.mathEngine = 0;
        window.codeHighlightEngine = 1;
        window.enableCodeLineNumber = false;
        window.codeHighlightTheme = 'cnblogs';
        window.darkModeCodeHighlightTheme = 'vs2015';
        window.isDarkCodeHighlightTheme = false;
        window.isDarkModeCodeHighlightThemeDark = true;
        window.isDisableCodeHighlighter = false;
        window.enableCodeThemeTypeFollowSystem = false;
        window.enableMacStyleCodeBlock = false;
    </script>
        <script>
            window.currentPostId = 14128974;
            window.currentPostDateAdded = '2020-12-13 16:24';
        </script>
    <script src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/jquery-3.3.1.min.js"></script>
    <script src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/blog-common.min.js"></script><style>.medium-zoom-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  opacity: 0;
  transition: opacity 300ms;
  will-change: opacity;
}

.medium-zoom--opened .medium-zoom-overlay {
  cursor: pointer;
  cursor: zoom-out;
  opacity: 1;
}

.medium-zoom-image {
  cursor: pointer;
  cursor: zoom-in;
  /*
    The `transition` is marked as "!important" for the animation to happen
    even though it's overriden by another inline `transition` style attribute.

    This is problematic with frameworks that generate inline styles on their
    images (e.g. Gatsby).

    See https://github.com/francoischalifour/medium-zoom/issues/110
   */
  transition: transform 300ms cubic-bezier(0.2, 0, 0.2, 1) !important;
}

.medium-zoom-image--hidden {
  visibility: hidden;
}

.medium-zoom-image--opened {
  position: relative;
  cursor: pointer;
  cursor: zoom-out;
  will-change: transform;
}
</style><script id="hljs-script" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/highlight.min.js" type="text/javascript" async=""></script>
    
<meta property="og:image" content="https://d33wubrfki0l68.cloudfront.net/9b0dada7cad04f51c17ea15ad41d4fe88d783cb7/3b7e1/post/programming/protobuf_avatar.png"><script id="hljs-language-protobuf" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/protobuf.min.js" type="text/javascript" async=""></script></head>
<body class="skin-bluesky has-navbar has-bannerbar hljs-engine">
    <a name="top"></a>
        <a href="https://www.cnblogs.com/cmt/p/18226431" onclick="countCreativeClicks(&#39;C0-阿里云-征文活动&#39;)" target="_blank" rel="nofollow">
            <div class="bannerbar forpc" style="background-size: contain;background-image: url(https://img2024.cnblogs.com/blog/35695/202405/35695-20240524121614762-1692171159.jpg);padding-left: 15px;">
                <img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/35695-20240521130941177-794658493.jpg" style="" onload="countCreativeImpressions(&#39;C0-阿里云-征文活动&#39;)">
                
                
                <span id="c0_impression" style="display:none"></span>
            </div>
        </a>
    <div id="top_nav" class="navbar forpc">
        <nav id="nav_main" class="navbar-main">
            <ul id="nav_left" class="navbar-list navbar-left">
                <li class="navbar-branding">
                    <a href="https://www.cnblogs.com/" title="开发者的网上家园" role="banner">
                        <img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/logo.svg" alt="博客园Logo">
                    </a>
                </li>
                <li><a href="https://cnblogs.vip/">会员</a></li>
                <li><a href="https://www.cnblogs.com/cmt/articles/18197617">众包</a></li>
                <li>
                    <a href="https://news.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-news&#39;)">新闻</a>
                </li>
                <li>
                    <a href="https://q.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-q&#39;)">博问</a>
                </li>
                <li>
                    <a href="https://ing.cnblogs.com/" onclick="countClicks(&#39;nav&#39;, &#39;skin-navbar-ing&#39;)">闪存</a>
                </li>
                <li><a href="https://market.cnblogs.com/" target="_blank">云市场</a></li>
            </ul>
            <ul id="nav_right" class="navbar-list navbar-right">
                <li>
                    <form id="zzk_search" class="navbar-search dropdown" action="https://zzk.cnblogs.com/s" method="get" role="search">
                        <input name="w" id="zzk_search_input" placeholder="代码改变世界" type="search" tabindex="3" autocomplete="off">
                        <button id="zzk_search_button" onclick="window.navbarSearchManager.triggerActiveOption()">
                            <img id="search_icon" class="focus-hidden" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/search.svg" alt="搜索">
                            <img class="hidden focus-visible" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/enter.svg" alt="搜索">
                        </button>
                        <ul id="navbar_search_options" class="dropdown-menu quick-search-menu">
                            <li tabindex="0" class="active" onclick="zzkSearch(event, document.getElementById(&#39;zzk_search_input&#39;).value)">
                                <div class="keyword-wrapper">
                                    <img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/search.svg" alt="搜索">
                                    <div class="keyword"></div>
                                </div>
                                <span class="search-area">所有博客</span>
                            </li>
                                    <li tabindex="1" onclick="zzkBlogSearch(event, &#39;a00ium&#39;, document.getElementById(&#39;zzk_search_input&#39;).value)">
                                        <div class="keyword-wrapper">
                                            <img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/search.svg" alt="搜索">
                                            <div class="keyword"></div>
                                        </div>
                                        <span class="search-area">当前博客</span>
                                    </li>
                        </ul>
                    </form>
                </li>
                <li id="navbar_login_status" class="navbar-list">
                    <a class="navbar-user-info navbar-blog" href="https://i.cnblogs.com/EditPosts.aspx?opt=1" alt="写随笔" title="写随笔" style="display: none;">
                        <img id="new_post_icon" class="navbar-icon" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/newpost.svg" alt="写随笔">
                    </a>
                    <a id="navblog-myblog-icon" class="navbar-user-info navbar-blog" href="https://passport.cnblogs.com/GetBlogApplyStatus.aspx" alt="我的博客" title="我的博客" style="display: none;">
                        <img id="myblog_icon" class="navbar-icon" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/myblog.svg" alt="我的博客">
                    </a>
                    <a class="navbar-user-info navbar-message navbar-icon-wrapper" href="https://msg.cnblogs.com/" alt="短消息" title="短消息" style="display: none;">
                        <img id="msg_icon" class="navbar-icon" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/message.svg" alt="短消息">
                        <span id="msg_count" style="display: none"></span>
                    </a>
                    <a id="navbar_lite_mode_indicator" data-current-page="blog" style="display: none" href="javascript:void(0)" alt="简洁模式" title="简洁模式启用，您在访问他人博客时会使用简洁款皮肤展示">
                        <img class="navbar-icon" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/lite-mode-on.svg" alt="简洁模式">
                    </a>
                    <div id="user_info" class="navbar-user-info dropdown" style="display: none;">
                        <a class="dropdown-button" href="https://home.cnblogs.com/">
                            <img id="user_icon" class="navbar-avatar" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/avatar-default.svg" alt="用户头像">
                        </a>
                        <div class="dropdown-menu">
                            <a id="navblog-myblog-text" href="https://passport.cnblogs.com/GetBlogApplyStatus.aspx">我的博客</a>
                            <a href="https://home.cnblogs.com/">我的园子</a>
                            <a href="https://account.cnblogs.com/settings/account">账号设置</a>
                            <a href="javascript:void(0)" id="navbar_lite_mode_toggle" title="简洁模式会使用简洁款皮肤显示所有博客">
    简洁模式 <img id="navbar_lite_mode_on" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/lite-mode-check.svg" class="hide" style="display: none;"><span id="navbar_lite_mode_spinner" class="hide">...</span>
</a>
                            <a href="javascript:void(0)" onclick="account.logout();">退出登录</a>
                        </div>
                    </div>
                    <a class="navbar-anonymous" href="https://account.cnblogs.com/signup" style="display: inline;">注册</a>
                    <a class="navbar-anonymous" href="javascript:void(0);" onclick="account.login()" style="display: inline;">登录</a>
                </li>
            </ul>
        </nav>
    </div>

    

    <!--done-->
<div id="home">
<div id="header">
	<div id="blogTitle">
        <a id="lnkBlogLogo" href="https://www.cnblogs.com/a00ium/"><img id="blogLogo" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/logo.gif" alt="返回主页"></a>		
		
<!--done-->
<h1><a id="Header1_HeaderTitle" class="headermaintitle HeaderMainTitle" href="https://www.cnblogs.com/a00ium">DaisyLinux</a>
</h1>
<h2></h2>




		
	</div><!--end: blogTitle 博客的标题和副标题 -->
	<div id="navigator">
		
<ul id="navList">
<li><a id="blog_nav_sitehome" class="menu" href="https://www.cnblogs.com/">
博客园</a>
</li>
<li>
<a id="blog_nav_myhome" class="menu" href="https://www.cnblogs.com/a00ium/">
首页</a>
</li>
<li>

<a id="blog_nav_newpost" class="menu" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">
新随笔</a>
</li>
<li>
<a id="blog_nav_contact" class="menu" href="https://msg.cnblogs.com/send/DaisyLinux">
联系</a></li>
<li>
<a id="blog_nav_rss" class="menu" href="javascript:void(0)" data-rss="https://www.cnblogs.com/a00ium/rss/">
订阅</a>
<!--<partial name="./Shared/_XmlLink.cshtml" model="Model" /></li>--></li>
<li>
<a id="blog_nav_admin" class="menu" href="https://i.cnblogs.com/">
管理</a>
</li>
</ul>


		<div class="blogStats">
			<span id="stats_post_count">随笔 - 494&nbsp; </span>
<span id="stats_article_count">文章 - 1&nbsp; </span>
<span id="stats-comment_count">评论 - 17&nbsp; </span>
<span id="stats-total-view-count">阅读 - 
<span title="总阅读数: 651759">
65万</span></span>

		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->
<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		<div id="post_detail">
    <!--done-->
    <div id="topics">
        <div class="post">
            <h1 class="postTitle">
                <a id="cb_post_title_url" class="postTitle2 vertical-middle" href="https://www.cnblogs.com/a00ium/p/14128974.html" title="发布于 2020-12-13 16:24">
    <span role="heading" aria-level="2">Python的基本Protobuf指南(序列化数据)</span>
    

</a><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button>

            </h1>
            <div class="clear"></div>
            <div class="postBody">
                <div id="cnblogs_post_body" class="blogpost-body blogpost-body-html">
<p class="post__lead"><img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/protobuf_avatar.png" alt="Python的基本Protobuf指南" class="medium-zoom-image"></p>
<div class="content post__content clearfix">
<p><span><span>协议缓冲区（Protobuf）是Google开发的与语言无关的数据序列化格式。</span><span>Protobuf之所以出色，原因如下：</span></span></p>
<ul>
<li>数据量低：<span>&nbsp;Protobuf使用二进制格式，该格式比JSON等其他格式更紧凑。</span></li>
<li>持久性：<span><span>&nbsp;Protobuf序列化是向后兼容的。</span><span>这意味着即使接口在此期间发生了更改，您也可以始终还原以前的数据。</span></span></li>
<li>按合同设计：<span>&nbsp;Protobuf要求使用显式标识符和类型来规范消息。</span></li>
<li>gRPC的要求：<span>&nbsp;gRPC（gRPC远程过程调用）是一种利用Protobuf格式的高效远程过程调用系统。</span></li>
</ul>
<p><span><span>就个人而言，我最喜欢Protobuf的是，如果强迫开发人员明确定义应用程序的接口。</span><span>这是一个改变规则的游戏，因为它使所有利益相关者都能理解界面设计并为之做出贡献。</span></span></p>
<p><span>在这篇文章中，我想分享我在Python应用程序中使用Protobuf的经验。</span></p>
<h2 id="installing-protobuf"><span>安装Protobuf</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h2>
<p><span><span>对于大多数系统，Protobuf必须从源代码安装。</span><span>在下面，我描述了Unix系统的安装：</span></span></p>
<p>1.从Git下载最新的Protobuf版本：</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_482175" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">wget https:</code><code class="csharp comments">//github.com/protocolbuffers/protobuf/releases/download/v3.12.4/protobuf-all-3.12.4.tar.gz</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<p>2.解压缩</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_572666" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">tar -xzf protobuf-all-3.12.4.tar.gz</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<p>3.安装：</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_592107" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">cd protobuf-3.12.4/ &amp;&amp; ./configure &amp;&amp; make &amp;&amp; sudo make install</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<p><span><span>4.验证安装（</span></span><code>protoc</code><span><span>现在应该可用！）</span></span></p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_104768" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">protocprotoc --version</code></div></div></td></tr></tbody></table></div></div>
<div class="cnblogs_Highlighter">

</div>
<p>　　</p>
</div>
<p>　　</p>
<p><span>一旦原型编译器可用，我们就可以开始。</span></p>
<h2 id="1-definition-of-protobuf-messages"><span>1. Protobuf消息的定义</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h2>
<p><span><span>要使用Protobuf，我们首先需要定义我们要传输的消息。</span><span>消息在</span></span><code>.proto</code><span><span>文件</span><span>内定义</span><span>。</span><span>请考虑</span></span><a href="https://developers.google.com/protocol-buffers/docs/proto3" rel="noopener">官方文档</a><span><span>以获取协议缓冲区语言的详细信息。</span><span>在这里，我仅提供一个简单的示例，旨在展示最重要的语言功能。</span></span></p>
<p><span><span>假设我们正在开发一个类似Facebook的社交网络，该社交网络完全是关于人及其联系的。</span><span>这就是为什么我们要为一个人建模消息。</span></span></p>
<p><span><span>一个人具有某些固有的特征（例如年龄，性别，身高），还具有我们需要建模的某些外在特征（例如朋友，爱好）。</span><span>让我们存储以下定义</span></span><code>src/interfaces/person.proto</code><span>：</span></p>
<div class="highlight">
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_229537" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">syntax = </code><code class="csharp string">"proto3"</code><code class="csharp plain">;</code></div><div class="line number2 index1 alt1">&nbsp;</div><div class="line number3 index2 alt2"><code class="csharp plain">import </code><code class="csharp string">"generated/person_info.proto"</code><code class="csharp plain">;</code></div><div class="line number4 index3 alt1">&nbsp;</div><div class="line number5 index4 alt2"><code class="csharp plain">package persons;</code></div><div class="line number6 index5 alt1">&nbsp;</div><div class="line number7 index6 alt2"><code class="csharp plain">message Person {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">PersonInfo info = 1; </code><code class="csharp comments">// characteristics of the person</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">repeated Friend friends = 2; </code><code class="csharp comments">// friends of the person</code></div><div class="line number10 index9 alt1"><code class="csharp plain">}</code></div><div class="line number11 index10 alt2">&nbsp;</div><div class="line number12 index11 alt1"><code class="csharp plain">message Friend {</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">float</code> <code class="csharp plain">friendship_duration = 1; </code><code class="csharp comments">// duration of friendship in days</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">repeated </code><code class="csharp keyword">string</code> <code class="csharp plain">shared_hobbies = 2; </code><code class="csharp comments">// shared interests</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">Person person = 3; </code><code class="csharp comments">// identity of the friend</code></div><div class="line number16 index15 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　<img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/90107-20201213162004186-1459866182.png" alt="" loading="lazy" class="medium-zoom-image"><img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/90107-20201213162603424-539681233.png" alt="" loading="lazy" class="medium-zoom-image"></p>
</div>
<p><span>请注意，我们引用的是另一个原始文件，</span><code>generated/person_info.proto</code><span>我们将其定义为：</span></p>
<div class="highlight">
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_447539" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">syntax = </code><code class="csharp string">"proto3"</code><code class="csharp plain">;</code></div><div class="line number2 index1 alt1">&nbsp;</div><div class="line number3 index2 alt2"><code class="csharp plain">package persons;</code></div><div class="line number4 index3 alt1">&nbsp;</div><div class="line number5 index4 alt2"><code class="csharp keyword">enum</code> <code class="csharp plain">Sex {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">M = 0; </code><code class="csharp comments">// male </code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">F = 1; </code><code class="csharp comments">// female</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">O = 2; </code><code class="csharp comments">// other</code></div><div class="line number9 index8 alt2"><code class="csharp plain">}</code></div><div class="line number10 index9 alt1">&nbsp;</div><div class="line number11 index10 alt2"><code class="csharp plain">message PersonInfo {</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">int32 age = 1; </code><code class="csharp comments">// age in years</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">Sex sex = 2; </code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">int32 height = 3; </code><code class="csharp comments">// height in cm</code></div><div class="line number15 index14 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　<img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/90107-20201213162817354-406510515.png" alt="" loading="lazy" class="medium-zoom-image"></p>
</div>
<p><span>不用担心这些定义对您还没有意义，我现在将解释最重要的关键字：</span></p>
<ul>
<li>语法<span><span>：语法定义了规范使用哪个版本的Protobuf。</span><span>我们正在使用</span></span><code>proto3</code><span>。</span></li>
<li>import<span>：如果根据另一条消息定义了一条消息，则需要使用</span><code>import</code><span><span>语句</span><span>将其包括在内</span><span>。</span><span>您可能想知道为什么导入</span></span><code>person.proto</code><span><span>？</span><span>我们稍后将对此进行更深入的研究-现在仅知道这是由于Python的导入系统所致。</span></span><code>generated/person_info.proto</code><code>interfaces/person_info.proto</code></li>
<li>package<span><span>：包定义了属于同一名称空间的消息。</span><span>这样可以防止名称冲突。</span></span></li>
<li>enum<span>：一个枚举定义一个枚举类型。</span></li>
<li>messsage<span>：消息是我们想使用Protobuf建模的一条信息。</span></li>
<li>repeat<span>：</span><code>repeated</code><span><span>关键字指示一个变量，该变量被解释为向量。</span><span>在我们的情况下，</span></span><code>friends</code><span>是</span><code>Friend</code><span><span>消息</span><span>的向量</span><span>。</span></span></li>
</ul>
<p><span><span>还要注意，每个消息属性都分配有一个唯一的编号。</span><span>该编号对于协议的向后兼容是必需的：一旦将编号分配给字段，则不应在以后的时间点对其进行修改。</span></span></p>
<p><span>现在我们有了应用程序的基本原型定义，我们可以开始生成相应的Python代码了。</span></p>
<h2 id="2-compilation-of-proto-files"><span>2.原始文件的编译</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h2>
<p><span>要将原始文件编译为Python对象，我们将使用Protobuf编译器</span><code>protoc</code><span>。</span></p>
<p><span>我们将使用以下选项调用原型编译器：</span></p>
<ul>
<li><code>--python_out</code><span>：将存储已编译的Python文件的目录</span></li>
<li><code>--proto_path</code><span><span>：由于原始文件不在项目的根文件夹中，因此我们需要使用替代文件。</span><span>通过指定</span></span><code>generated=./src/interfaces</code><span><span>，编译器知道</span><span>在导入其他原始消息时</span><span>，我们要使用生成文件的路径（</span></span><code>generated</code><span>），而不是接口的位置（</span><code>src/interfaces</code><span>）。</span></li>
</ul>
<p><span>有了这种了解，我们可以像下面这样编译原始文件：</span></p>
<div class="highlight">
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_901116" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">mkdir src/generated</code></div><div class="line number2 index1 alt1"><code class="csharp plain">protoc src/interfaces/person_info.proto --python_out src/ --proto_path generated=./src/interfaces/</code></div><div class="line number3 index2 alt2"><code class="csharp plain">protoc src/interfaces/person.proto --python_out src/ --proto_path generated=./src/interfaces/</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
</div>
<p><span>执行完这些命令后，文件</span><code>generated/person_pb2.py</code><span>和</span><code>generated/person_info_pb2.py</code><span><span>应该存在。</span><span>例如，&nbsp;</span></span><code>person_pb2.py</code><span>如下所示：</span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-python hljs highlighter-hljs" data-lang="python">_PERSON = _descriptor.Descriptor(
  name=<span class="hljs-string">'Person'</span>,
  full_name=<span class="hljs-string">'persons.Person'</span>,
  filename=<span class="hljs-literal">None</span>,
  file=DESCRIPTOR,
  containing_type=<span class="hljs-literal">None</span>,
  create_key=_descriptor._internal_create_key,
  fields=[
...
</code></pre>
<p><img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/90107-20201213162442927-1270568896.png" alt="" loading="lazy" class="medium-zoom-image">&nbsp;</p>
</div>
<p><span><span>生成的Python代码并非真正可读。</span><span>但这没关系，因为我们只需要知道</span></span><code>person_pb2.py</code><span>可以用于构造可序列化的Protobuf对象即可。</span></p>
<h2 id="3-serialization-of-protobuf-objects"><span>3. Protobuf对象的序列化</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h2>
<p><span><span>在我们以有意义的方式序列化Protobuf对象之前，我们需要用一些数据填充它。</span><span>让我们生成一个有一个朋友的人：</span></span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-python hljs highlighter-hljs" data-lang="python"><span class="hljs-comment"># fill protobuf objects</span>
<span class="hljs-keyword">import</span> generated.person_pb2 <span class="hljs-keyword">as</span> person_pb2
<span class="hljs-keyword">import</span> generated.person_info_pb2 <span class="hljs-keyword">as</span> person_info_pb2
<span class="hljs-comment">############</span>
<span class="hljs-comment"># define friend for person of interest</span>
<span class="hljs-comment">#############</span>
friend_info = person_info_pb2.PersonInfo()
friend_info.age = <span class="hljs-number">40</span>
friend_info.sex = person_info_pb2.Sex.M
friend_info.height = <span class="hljs-number">165</span>
friend_person = person_pb2.Person()
friend_person.info.CopyFrom(friend_info)
friend_person.friends.extend([])  <span class="hljs-comment"># no friends :-(</span>
<span class="hljs-comment">#######</span>
<span class="hljs-comment"># define friendship characteristics</span>
<span class="hljs-comment">########</span>
friendship = person_pb2.Friend()
friendship.friendship_duration = <span class="hljs-number">365.1</span>
friendship.shared_hobbies.extend([<span class="hljs-string">"books"</span>, <span class="hljs-string">"daydreaming"</span>, <span class="hljs-string">"unicorns"</span>])
friendship.person.CopyFrom(friend_person)
<span class="hljs-comment">#######</span>
<span class="hljs-comment"># assign the friend to the friend of interest</span>
<span class="hljs-comment">#########</span>
person_info = person_info_pb2.PersonInfo()
person_info.age = <span class="hljs-number">30</span>
person_info.sex = person_info_pb2.Sex.M
person_info.height = <span class="hljs-number">184</span>
person = person_pb2.Person()
person.info.CopyFrom(person_info)
person.friends.extend([friendship])  <span class="hljs-comment"># person with a single friend</span>
</code></pre>
</div>
<p><span><span>请注意，我们通过直接分配填充了所有琐碎的数据类型（例如，整数，浮点数和字符串）。</span><span>仅对于更复杂的数据类型，才需要使用其他一些功能。</span><span>例如，我们利用</span></span><code>extend</code><span>来填充重复的Protobuf字段并</span><code>CopyFrom</code><span>填充Protobuf子消息。</span></p>
<p><span>要序列化Protobuf对象，我们可以使用</span><code>SerializeToString()</code><span><span>函数。</span><span>此外，我们还可以使用以下</span></span><code>str()</code><span><span>函数将</span><span>Protobuf对象输出为人类可读的字符串</span><span>：</span></span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-python hljs highlighter-hljs" data-lang="python"><span class="hljs-comment"># serialize proto object</span>
<span class="hljs-keyword">import</span> os
out_dir = <span class="hljs-string">"proto_dump"</span>
<span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(os.path.join(out_dir, <span class="hljs-string">"person.pb"</span>), <span class="hljs-string">"wb"</span>) <span class="hljs-keyword">as</span> f:
    <span class="hljs-comment"># binary output</span>
    f.write(person.SerializeToString())
<span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(os.path.join(out_dir, <span class="hljs-string">"person.protobuf"</span>), <span class="hljs-string">"w"</span>) <span class="hljs-keyword">as</span> f:
    <span class="hljs-comment"># human-readable output for debugging</span>
    f.write(<span class="hljs-built_in">str</span>(person))
</code></pre>
</div>
<p><span>执行完代码段后，可以在</span><code>proto_dump/person.protobuf</code><span><span>以下</span><span>位置找到生成的人类可读的Protobuf消息</span><span>：</span></span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-protobuf highlighter-hljs hljs" data-lang="protobuf">info {
  age: <span class="hljs-number">30</span>
  height: <span class="hljs-number">184</span>
}
friends {
  friendship_duration: <span class="hljs-number">365.1000061035156</span>
  shared_hobbies: <span class="hljs-string">"books"</span>
  shared_hobbies: <span class="hljs-string">"daydreaming"</span>
  shared_hobbies: <span class="hljs-string">"unicorns"</span>
  person {
    info {
      age: <span class="hljs-number">40</span>
      height: <span class="hljs-number">165</span>
    }
  }
}
</code></pre>
</div>
<p><span><span>请注意，此人的信息既不显示该人的性别，也不显示其朋友的性别。</span><span>这不是Bug，而是Protobuf的功能：</span></span><code>0</code><span><span>永远不会打印</span><span>值为的条目</span><span>。</span></span><code>sex</code><span><span>由于这两个人都是男性，</span><span>因此</span><span>此处未显示</span></span><code>0</code><span>。</span></p>
<h2 id="4-automated-protobuf-compilation"><span>4.自动化的Protobuf编译</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h2>
<p><span><span>在开发过程中，每次更改后必须重新编译原始文件可能会变得很乏味。</span><span>要在安装开发Python软件包时自动编译原始文件，我们可以使用该</span></span><code>setup.py</code><span>脚本。</span></p>
<p><span>让我们创建一个函数，该函数为</span><code>.proto</code><span><span>目录中的</span><span>所有</span><span>文件</span><span>生成Protobuf代码</span></span><code>src/interfaces</code><span>并将其存储在下</span><code>src/generated</code><span>：</span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-python hljs highlighter-hljs" data-lang="python"><span class="hljs-keyword">import</span> pathlib
<span class="hljs-keyword">import</span> os
<span class="hljs-keyword">from</span> subprocess <span class="hljs-keyword">import</span> check_call

<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_proto_code</span>():
    proto_interface_dir = <span class="hljs-string">"./src/interfaces"</span>
    generated_src_dir = <span class="hljs-string">"./src/generated/"</span>
    out_folder = <span class="hljs-string">"src"</span>
    <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(generated_src_dir):
        os.mkdir(generated_src_dir)
    proto_it = pathlib.Path().glob(proto_interface_dir + <span class="hljs-string">"/**/*"</span>)
    proto_path = <span class="hljs-string">"generated="</span> + proto_interface_dir
    protos = [<span class="hljs-built_in">str</span>(proto) <span class="hljs-keyword">for</span> proto <span class="hljs-keyword">in</span> proto_it <span class="hljs-keyword">if</span> proto.is_file()]
    check_call([<span class="hljs-string">"protoc"</span>] + protos + [<span class="hljs-string">"--python_out"</span>, out_folder, <span class="hljs-string">"--proto_path"</span>, proto_path])
</code></pre>
</div>
<p><span>接下来，我们需要覆盖</span><code>develop</code><span>命令，以便每次安装软件包时都调用该函数：</span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-python hljs highlighter-hljs" data-lang="python"><span class="hljs-keyword">from</span> setuptools.command.develop <span class="hljs-keyword">import</span> develop
<span class="hljs-keyword">from</span> setuptools <span class="hljs-keyword">import</span> setup, find_packages

<span class="hljs-keyword">class</span> <span class="hljs-title class_">CustomDevelopCommand</span>(<span class="hljs-title class_ inherited__">develop</span>):
    <span class="hljs-string">"""Wrapper for custom commands to run before package installation."""</span>
    uninstall = <span class="hljs-literal">False</span>

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">run</span>(<span class="hljs-params">self</span>):
        develop.run(self)

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">install_for_development</span>(<span class="hljs-params">self</span>):
        develop.install_for_development(self)
        generate_proto_code()

setup(
    name=<span class="hljs-string">'testpkg'</span>,
    version=<span class="hljs-string">'1.0.0'</span>,
    package_dir={<span class="hljs-string">''</span>: <span class="hljs-string">'src'</span>},
    cmdclass={
        <span class="hljs-string">'develop'</span>: CustomDevelopCommand, <span class="hljs-comment"># used for pip install -e ./</span>
    },
    packages=find_packages(where=<span class="hljs-string">'src'</span>)
)
</code></pre>
</div>
<p><span>下次我们运行时</span><code>pip install -e ./</code><span>，Protobuf文件将在中自动生成</span><code>src/generated</code><span>。</span></p>
<h2 id="how-much-space-are-we-saving"><span>我们节省多少空间？</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h2>
<p><span><span>之前，我提到Protobuf的优点之一是其二进制格式。</span><span>在这里，我们将通过比较Protobuf消息的大小和</span></span><code>Person</code><span><span>相应的JSON</span><span>来考虑此优势</span><span>：</span></span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-json hljs highlighter-hljs" data-lang="json"><span class="hljs-attr">"person"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
    <span class="hljs-attr">"info"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
      <span class="hljs-attr">"age"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">30</span><span class="hljs-punctuation">,</span>
      <span class="hljs-attr">"height"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">184</span>
    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>
    <span class="hljs-attr">"friends"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
      <span class="hljs-attr">"friendship_duration"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">365.1000061035156</span><span class="hljs-punctuation">,</span>
      <span class="hljs-attr">"shared_hobbies"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"books"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"daydreaming"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"unicorns"</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>
      <span class="hljs-attr">"person"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
        <span class="hljs-attr">"info"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
          <span class="hljs-attr">"age"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">40</span><span class="hljs-punctuation">,</span>
          <span class="hljs-attr">"height"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">165</span>
        <span class="hljs-punctuation">}</span>
      <span class="hljs-punctuation">}</span>
    <span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span>
</code></pre>
</div>
<p><span><span>比较JSON和Protobuf文本表示形式，结果发现JSON实际上更紧凑，因为它的列表表示形式更加简洁。</span><span>但是，这令人产生误解，因为我们对二进制Protobuf格式感兴趣。</span></span></p>
<p><span>当比较</span><code>Person</code><span><span>对象</span><span>的二进制Protobuf和JSON占用的字节数时</span><span>，我们发现以下内容：</span></span></p>
<div class="highlight">
<pre class="highlighter-hljs" highlighted="true"><code class="language-bash hljs highlighter-hljs" data-lang="bash"><span class="hljs-built_in">du</span> -b person.pb
53      person.pb

<span class="hljs-built_in">du</span> -b person.json 
304     person.json
</code></pre>
</div>
<h3 id="here-protobuf-is-5-times-smaller-than-json"><span>在这里，Protobuf比JSON小5倍</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h3>
<p><span><span>二进制Protobuf（53个字节）</span><span>比相应的JSON（304个字节）</span></span>小5倍<span><span>以上。</span><span>请注意，如果我们使用gRPC协议传输二进制Protobuf，则只能达到此压缩级别。</span></span></p>
<p><span><span>如果不选择gRPC，则常见的模式是使用base64编码对二进制Protobuf数据进行编码。</span><span>尽管此编码不可撤销地将有效载荷的大小增加了33％，但仍比相应的REST有效载荷小得多。</span></span></p>
<h2 id="summary"><span>概要</span><button class="cnblogs-toc-button" title="显示目录导航" aria-expanded="false"></button></h2>
<p><span><span>Protobuf是数据序列化的理想格式。</span><span>它比JSON小得多，并且允许接口的显式定义。</span><span>由于其良好的性能，我建议在所有使用足够复杂数据的项目中使用Protobuf。</span><span>尽管Protobuf需要初步的时间投入，但我敢肯定它会很快得到回报。</span></span></p>
</div>
</div>
<div class="clear"></div>
<div id="blog_post_info_block" role="contentinfo">




    <div id="blog_post_info">
<div id="green_channel">
        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(14128974,cb_blogId,1);green_channel_success(this,&#39;谢谢推荐！&#39;);">好文要顶</a>
        <a id="green_channel_follow" onclick="follow(&#39;c2038c93-19a8-de11-ba8f-001cf0cd104b&#39;);" href="javascript:void(0);">关注我</a>
    <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
    <a id="green_channel_wechat" href="javascript:void(0);" onclick="shareManager.wechatShare()">微信分享</a>
</div>
<div id="author_profile">
    <div id="author_profile_info" class="author_profile_info">
            <a href="https://home.cnblogs.com/u/a00ium/" target="_blank"><img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/20150630162125.png" class="author_avatar" alt=""></a>
        <div id="author_profile_detail" class="author_profile_info">
            <a href="https://home.cnblogs.com/u/a00ium/">DaisyLinux</a>
            <br>
            <a href="https://home.cnblogs.com/u/a00ium/followers/">粉丝 - <span class="follower-count">51</span></a>
            <a href="https://home.cnblogs.com/u/a00ium/followees/">关注 - <span class="following-count">2</span></a><br>
        </div>
    </div>
    <div class="clear"></div>
    <div id="author_profile_honor"></div>
    <div id="author_profile_follow" class="follow-tip">
                <a href="javascript:void(0);" onclick="follow(&#39;c2038c93-19a8-de11-ba8f-001cf0cd104b&#39;);return false;">+加关注</a>
    </div>
</div>
<div id="div_digg">
    <div class="diggit" onclick="votePost(14128974,&#39;Digg&#39;)">
        <span class="diggnum" id="digg_count">2</span>
    </div>
    <div class="buryit" onclick="votePost(14128974,&#39;Bury&#39;)">
        <span class="burynum" id="bury_count">0</span>
    </div>
    <div class="clear"></div>
    <div class="diggword" id="digg_tips">
    </div>
        <div id="vip_tip"><a class="tip" href="https://cnblogs.vip/" target="_blank">升级成为会员</a></div>
</div>

<script type="text/javascript">
    currentDiggType = 0;
</script>
</div>
    <div class="clear"></div>
    <div id="post_next_prev">

    <a href="https://www.cnblogs.com/a00ium/p/14128887.html" class="p_n_p_prefix">« </a> 上一篇：    <a href="https://www.cnblogs.com/a00ium/p/14128887.html" data-featured-image="" title="发布于 2020-12-13 16:03">协议缓冲区基础：Python</a>
    <br>
    <a href="https://www.cnblogs.com/a00ium/p/14152374.html" class="p_n_p_prefix">» </a> 下一篇：    <a href="https://www.cnblogs.com/a00ium/p/14152374.html" data-featured-image="" title="发布于 2020-12-17 22:31">从未如此简单，一文带你逆袭Kafka</a>

</div>
</div>
            </div>
            <div class="postDesc">posted @ 
<span id="post-date" data-last-update-days="1283.012179046633" data-date-created="BlogServer.Application.Dto.BlogPost.BlogPostDto" data-date-updated="2020-12-13 16:29" aria-expanded="false">2020-12-13 16:24</span>&nbsp;
<a href="https://www.cnblogs.com/a00ium">DaisyLinux</a>&nbsp;
阅读(<span id="post_view_count">21550</span>)&nbsp;
评论(<span id="post_comment_count">2</span>)&nbsp;
<a href="https://i.cnblogs.com/EditPosts.aspx?postid=14128974" rel="nofollow">编辑</a>&nbsp;
<a href="javascript:void(0)" onclick="AddToWz(14128974);return false;">收藏</a>&nbsp;
<a href="javascript:void(0)" onclick="reportManager.report({ currentUserId: &#39;&#39;, targetType: &#39;blogPost&#39;, targetId: &#39;14128974&#39;, targetLink: &#39;https://www.cnblogs.com/a00ium/p/14128974.html&#39;, title: &#39;Python的基本Protobuf指南(序列化数据)&#39; })">举报</a>
</div>
        </div>
	    
	    
    </div><!--end: topics 文章、评论容器-->
</div>
<script>
    var cb_entryId = 14128974, cb_entryCreatedDate = '2020-12-13 16:24', cb_postType = 1, cb_postTitle = 'Python的基本Protobuf指南(序列化数据)';
    var allowComments = true, cb_blogId = 233489, cb_blogApp = 'a00ium', cb_blogUserGuid = 'c2038c93-19a8-de11-ba8f-001cf0cd104b';
    mermaidRender.render()
    markdown_highlight()
    zoomManager.apply("#cnblogs_post_body img:not(.code_img_closed):not(.code_img_opened)");    
</script>
<a id="!comments"></a>
<div id="blog-comments-placeholder"></div>
<div id="comment_form" class="commentform">
    <a name="commentform"></a>
    <div id="divCommentShow"></div>
    <div id="comment_nav">
            <a class="comment-nav-left forpc" href="https://cnblogs.vip/" target="_blank">会员力量，点亮园子希望</a>
        <div class="comment-nav-right">
            <span id="span_refresh_tips"></span><a href="https://www.cnblogs.com/a00ium/p/14128974.html#" onclick="return RefreshPage();">刷新页面</a><a href="https://www.cnblogs.com/a00ium/p/14128974.html#top">返回顶部</a>
        </div>
    </div>
    <div id="comment_form_container"><div class="login_tips">
    登录后才能查看或发表评论，立即 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return account.login(&#39;!comments&#39;);">登录</a> 或者
    <a href="https://www.cnblogs.com/">逛逛</a> 博客园首页
</div>
</div>
    <div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
        <div id="cnblogs_ch"><a href="https://www.cnblogs.com/cmt/p/18239927" target="_blank" onclick="gtag(&#39;event&#39;, &#39;click&#39;, {&#39;event_category&#39;: &#39;ad&#39;, &#39;event_label&#39;: &#39;T2-阿里云-通义灵码&#39;})">【推荐】「指间灵动，快码加编」：通义灵码，再次降临博客园</a><br><a href="https://www.cnblogs.com/cmt/p/18226431" target="_blank" onclick="gtag(&#39;event&#39;, &#39;click&#39;, {&#39;event_category&#39;: &#39;ad&#39;, &#39;event_label&#39;: &#39;T2-阿里云-征文&#39;})">【推荐】这场阿里云开发者社区有奖征文活动，期待您出文相助</a><br><a href="https://www.finclip.com/?channel=cnblog2024" target="_blank" onclick="gtag(&#39;event&#39;, &#39;click&#39;, {&#39;event_category&#39;: &#39;ad&#39;, &#39;event_label&#39;: &#39;T2-凡泰极客&#39;})">【推荐】凡泰极客：跨越技术“鸿”沟，小程序一键生成鸿蒙App</a><br><a href="https://click.aliyun.com/m/1000394160/" target="_blank" onclick="gtag(&#39;event&#39;, &#39;click&#39;, {&#39;event_category&#39;: &#39;ad&#39;, &#39;event_label&#39;: &#39;T2-阿里云-618&#39;})">【推荐】阿里云创新加速季，5亿补贴享不停，上云礼包抢先领</a><br></div>
    <div id="opt_under_post"></div>
        <div id="cnblogs_c1" class="under-post-card">
            <a href="https://cnblogs.vip/" rel="nofollow" target="_blank" onclick="countCreativeClicks(&#39;C1-博客园-会员&#39;)">
                <img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/35695-20240328092537879-1189167464.jpg" onload="countCreativeImpressions(&#39;C1-博客园-会员&#39;)" alt="">
                <span id="c1_impression" style="display:none"></span>
            </a>
        </div>
    <div id="under_post_card1"><div class="under-post-card">
<b>编辑推荐：</b>
<br>

· <a href="https://www.cnblogs.com/binlovetech/p/18253193" target="_blank">FinalReference 如何使 GC 过程变得拖拖拉拉</a>
    <br>
· <a href="https://www.cnblogs.com/wzh2010/p/18031212" target="_blank">千万级流量冲击下，如何保证极致性能</a>
    <br>
· <a href="https://www.cnblogs.com/coco1s/p/18243384" target="_blank">「现代 CSS」标准滚动条控制规范</a>
    <br>
· <a href="https://www.cnblogs.com/bt4girls/p/18241919" target="_blank">智能小车开发篇 - 低时延直播测试</a>
    <br>
· <a href="https://www.cnblogs.com/binlovetech/p/18245598" target="_blank">以 ZGC 为例，谈一谈 JVM 是如何实现 Reference 语义的</a>
    <br>
</div></div>
    <div id="under_post_card2"><div class="itnews under-post-card">
    <b>阅读排行：</b>
    <br>
 ·          <a href="https://www.cnblogs.com/cmt/p/18251665" target="_blank">博客园众包平台：50w+驱动开发大单，全园找人接单</a>
        <br>
 ·          <a href="https://www.cnblogs.com/xueweihan/p/18253627" target="_blank">开源的网络瑞士军刀「GitHub 热点速览」</a>
        <br>
 ·          <a href="https://www.cnblogs.com/xiezhr/p/18251683" target="_blank">阿里也出手了！Spring CloudAlibaba AI问世了</a>
        <br>
 ·          <a href="https://www.cnblogs.com/MeteorSeed/p/18240700" target="_blank">【译】向您介绍改版的 Visual Studio 资源管理器</a>
        <br>
 ·          <a href="https://www.cnblogs.com/strick/p/18183911" target="_blank">带团队后的日常思考（十五）</a>
        <br>
</div></div>
    <div id="HistoryToday" class="under-post-card"></div>
    <script type="text/javascript">
        var commentManager = new blogCommentManager();
        commentManager.renderComments(0);
        fixPostBody();
        window.footnoteTipManager.generateFootnoteTips();

            window.tocManager.displayDisableTocTips = false;
            window.tocManager.generateToc();
            
                setTimeout(function() { countViews(cb_blogId, cb_entryId); }, 50);
            
            deliverT2();
            deliverC1C2();
            loadNewsAndKb();
            
                LoadPostCategoriesTags(cb_blogId, cb_entryId);
            
            LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
            GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
            loadOptUnderPost();
            GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);
                </script>
</div>

	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->
	<div id="sideBar">
		<div id="sideBarMain">
			<div id="sidebar_news" class="newsItem">
    <h3 class="catListTitle">公告</h3>
<div id="blog-news">    
    <div id="sidebar_news_content">
<div id="profile_block">
    昵称：
    <a href="https://home.cnblogs.com/u/a00ium/">
        DaisyLinux
    </a>
    <br>
    园龄：
    <a href="https://home.cnblogs.com/u/a00ium/" title="入园时间：2009-09-23">
        14年8个月
    </a>
    <br>
    粉丝：
    <a class="follower-count" href="https://home.cnblogs.com/u/a00ium/followers/">
        51
    </a>
    <br>
    关注：
    <a class="folowing-count" href="https://home.cnblogs.com/u/a00ium/followees/">
        2
    </a>
    <div id="p_b_follow" class="follow-tip">
<a href="javascript:void(0)" onclick="follow(&#39;c2038c93-19a8-de11-ba8f-001cf0cd104b&#39;)">+加关注</a></div>
    <script>getFollowStatus('c2038c93-19a8-de11-ba8f-001cf0cd104b');</script>
</div>
</div>
</div>
<script>loadBlogNews();</script>

 
</div>
<div id="sidebar_c3"></div>
			<div id="blog-calendar" style="">

<table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="Calendar" border="0">
    <tbody>
        <tr>
            <td colspan="7">
                <table class="CalTitle" cellspacing="0" border="0">
                    <tbody>
                        <tr>
                            <td class="CalNextPrev">
                                <a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2024/05/18&#39;); return false;">&lt;</a>
                            </td>
                            <td align="center">2024年6月</td>
                            <td align="right" class="CalNextPrev">
                                <a href="javascript:void(0);" onclick="loadBlogCalendar(&#39;2024/07/18&#39;); return false;">&gt;</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </td>
        </tr>
    <tr>
        <th class="CalDayHeader" align="center" abbr="日" scope="col">日</th>
        <th class="CalDayHeader" align="center" abbr="一" scope="col">一</th>
        <th class="CalDayHeader" align="center" abbr="二" scope="col">二</th>
        <th class="CalDayHeader" align="center" abbr="三" scope="col">三</th>
        <th class="CalDayHeader" align="center" abbr="四" scope="col">四</th>
        <th class="CalDayHeader" align="center" abbr="五" scope="col">五</th>
        <th class="CalDayHeader" align="center" abbr="六" scope="col">六</th>
    </tr>
            <tr>
                            <td class="CalOtherMonthDay" align="center">26</td>
                            <td class="CalOtherMonthDay" align="center">27</td>
                            <td class="CalOtherMonthDay" align="center">28</td>
                            <td class="CalOtherMonthDay" align="center">29</td>
                            <td class="CalOtherMonthDay" align="center">30</td>
                            <td class="CalOtherMonthDay" align="center">31</td>
                    <td class="CalWeekendDay" align="center">
                        1
                    </td>
            </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            2
                        </td>
                            <td class="" align="center">
                                3
                            </td>
                            <td class="" align="center">
                                4
                            </td>
                            <td class="" align="center">
                                5
                            </td>
                            <td class="" align="center">
                                6
                            </td>
                            <td class="" align="center">
                                7
                            </td>
                        <td class="CalWeekendDay" align="center">
                            8
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            9
                        </td>
                            <td class="" align="center">
                                10
                            </td>
                            <td class="" align="center">
                                11
                            </td>
                            <td class="" align="center">
                                12
                            </td>
                            <td class="" align="center">
                                13
                            </td>
                            <td class="" align="center">
                                14
                            </td>
                        <td class="CalWeekendDay" align="center">
                            15
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            16
                        </td>
                            <td class="" align="center">
                                17
                            </td>
                            <td class="CalTodayDay" align="center">
                                18
                            </td>
                            <td class="" align="center">
                                19
                            </td>
                            <td class="" align="center">
                                20
                            </td>
                            <td class="" align="center">
                                21
                            </td>
                        <td class="CalWeekendDay" align="center">
                            22
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            23
                        </td>
                            <td class="" align="center">
                                24
                            </td>
                            <td class="" align="center">
                                25
                            </td>
                            <td class="" align="center">
                                26
                            </td>
                            <td class="" align="center">
                                27
                            </td>
                            <td class="" align="center">
                                28
                            </td>
                        <td class="CalWeekendDay" align="center">
                            29
                        </td>
                </tr>
                <tr>
                        <td class="CalWeekendDay" align="center">
                            30
                        </td>
                            <td class="CalOtherMonthDay" align="center">
                                1
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                2
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                3
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                4
                            </td>
                            <td class="CalOtherMonthDay" align="center">
                                5
                            </td>
                        <td class="CalOtherMonthDay" align="center">
                            6
                        </td>
                </tr>
    </tbody>
</table></div><script>loadBlogDefaultCalendar();</script>			
			<div id="leftcontentcontainer">
				<div id="blog-sidecolumn"><!-- 搜索 -->
<div id="sidebar_search" class="sidebar-block">
    <div class="mySearch my-search">
        <h3 class="catListTitle">搜索</h3>
        <div id="sidebar_search_box">
            <div id="widget_my_zzk" class="div_my_zzk">
                <input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="找找看" id="btnZzk" class="btn_my_zzk">
            </div>
            
        </div>
    </div>
</div>

<!-- 常用链接 -->
<div id="sidebar_shortcut" class="sidebar-block"><div class="catListLink">
<h3 class="catListTitle">
常用链接
</h3>
<ul>
    <li><a href="https://www.cnblogs.com/a00ium/p/" title="我的博客的随笔列表">我的随笔</a></li>
<li><a href="https://www.cnblogs.com/a00ium/MyComments.html" title="我的发表过的评论列表">我的评论</a></li>
<li><a href="https://www.cnblogs.com/a00ium/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li>
<li><a href="https://www.cnblogs.com/a00ium/comments" title="我的博客的评论列表">最新评论</a></li>
<li><a href="https://www.cnblogs.com/a00ium/tag/" title="我的博客的标签列表">我的标签</a></li>

</ul>
</div>

</div>

<!-- 最新随笔 -->


<!-- 我的标签 -->
<div id="sidebar_toptags" class="sidebar-block"></div>

<!-- 积分与排名 -->


<!-- 随笔分类、随笔档案、文章分类、新闻分类、相册、链接 -->
<div id="sidebar_categories">

    <div id="sidebar_postarchive" class="catListPostArchive sidebar-block">
        <h3 class="catListTitle">
            
随笔档案


        </h3>

        <ul>

                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2024/05" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2024年5月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2024/04" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2024年4月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2024/01" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2024年1月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2023/10" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2023年10月(3)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2023/08" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2023年8月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2023/04" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2023年4月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2023/01" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2023年1月(3)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/12" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年12月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/11" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年11月(4)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/10" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年10月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/09" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年9月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/08" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年8月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/05" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年5月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/04" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年4月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="true" style="display: block">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/03" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年3月(5)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2022/01" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2022年1月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/12" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年12月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/11" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年11月(7)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/10" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年10月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/09" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年9月(4)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/08" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年8月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/07" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年7月(3)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/06" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年6月(4)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/05" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年5月(3)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/04" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年4月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/02" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年2月(8)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2021/01" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2021年1月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/12" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年12月(20)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/11" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年11月(13)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/10" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年10月(33)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/09" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年9月(7)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/08" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年8月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/07" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年7月(7)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/06" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年6月(5)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2020/02" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2020年2月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/10" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年10月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/07" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年7月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/06" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年6月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/05" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年5月(58)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/04" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年4月(1)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/03" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年3月(128)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/02" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年2月(105)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2019/01" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2019年1月(34)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2018/06" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2018年6月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2017/07" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2017年7月(2)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2017/03" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2017年3月(4)</a>
 
                </li>                
                <li data-category-list-item-visible="false" style="display: none">
                    
<a href="https://www.cnblogs.com/a00ium/p/archive/2017/01" style="--cnb-category-item-link-indent-size: calc(0 * 1em)" class="category-item-link" rel="" target="">2017年1月(1)</a>
 
                </li>                
            <li>
                <a href="javascript:void(0)" onclick="sideColumnManager.loadMore(this)">更多</a>
            </li>
        </ul>


    </div>    
</div>

<!-- 最新评论 -->
<!-- 阅读排行榜 -->
<div id="sidebar_topviewedposts" class="sidebar-block"><div class="catListView">
    <h3 class="catListTitle">
        <a href="https://www.cnblogs.com/a00ium/most-viewed" class="sidebar-card-title-a">
    阅读排行榜
</a>

    </h3>
    <div id="TopViewPostsBlock">
        <ul style="word-break:break-all">
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/13874909.html">
                            1. 在Python-Pandas中循环或遍历数据框的所有或某些列(26795)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/14128974.html">
                            2. Python的基本Protobuf指南(序列化数据)(21546)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/10867331.html">
                            3. linux shell 获取文件夹全文绝对路径(17265)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/10360494.html">
                            4. jmeter如何设置全局变量以及调用方法(15711)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/13875119.html">
                            5. Python | 查找给定字符串中字符的位置(15368)
                        </a>
                    </li>
        </ul>
    </div>
</div></div>

<!-- 评论排行榜 -->
<div id="sidebar_topcommentedposts" class="sidebar-block"><div class="catListFeedback">
    <h3 class="catListTitle">
        <a href="https://www.cnblogs.com/a00ium/most-commented" class="sidebar-card-title-a">评论排行榜</a>

    </h3>
    <div id="TopFeedbackPostsBlock">
        <ul style="word-break:break-all">
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/14128974.html">
                            1. Python的基本Protobuf指南(序列化数据)(2)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/10953106.html">
                            2. KAFKA 节点配置问题(2)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/10849848.html">
                            3. JMeter进行Apache Kafka负载测试(2)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/10412375.html">
                            4. JSON JSONPath(2)
                        </a>
                    </li>
                    <li>
                        <a href="https://www.cnblogs.com/a00ium/p/14153083.html">
                            5. Go版本 gRPC快速入门(1)
                        </a>
                    </li>
        </ul>
    </div>
</div></div>

<!-- 推荐排行榜 -->
<div id="sidebar_topdiggedposts" class="sidebar-block">
<div id="topdigg_posts_wrap">
    <div class="catListView">
        <h3 class="catListTitle">
            <a href="https://www.cnblogs.com/a00ium/most-liked" class="sidebar-card-title-a">推荐排行榜</a>

        </h3>
        <div id="TopDiggPostsBlock">
            <ul style="word-break: break-all">
                        <li>
                            <a href="https://www.cnblogs.com/a00ium/p/14128974.html">
                                1. Python的基本Protobuf指南(序列化数据)(2)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/a00ium/p/10462892.html">
                                2. JMETER结果分析(2)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/a00ium/p/15337832.html">
                                3. 最全的Pycharm debug技巧，「建议收藏」(1)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/a00ium/p/15039199.html">
                                4. pycharm自动生成文件注释和函数注释(1)
                            </a>
                        </li>
                        <li>
                            <a href="https://www.cnblogs.com/a00ium/p/14875138.html">
                                5. Python 中将 Pandas DataFrame 转换为 JSON？(1)
                            </a>
                        </li>
            </ul>
        </div>
    </div>
</div></div><div id="sidebar_recentcomments" class="sidebar-block"><div class="catListComment">
<h3 class="catListTitle"><a href="https://www.cnblogs.com/a00ium/comments" class="sidebar-card-title-a">最新评论</a></h3>
    <div class="RecentCommentBlock">
        <ul>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/a00ium/p/10360443.html">1. Re:Jmeter 自动化测试报告扩展(转 Todo 需要修正)</a></li>
                <li class="recent_comment_body"><p>您好，我套用你的xsl样式，但是只有一个接口的Response Data json化数据了，其他的接口的Response Data显示还是 Text<br>
希望得到您的知道</p>
</li>
                <li class="recent_comment_author">--有菜有多余的小测试</li>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/a00ium/p/11692273.html">2. Re:Kafka Consumer Lag Monitoring</a></li>
                <li class="recent_comment_body"><p>牛啊~</p>
</li>
                <li class="recent_comment_author">--规格严格-功夫到家</li>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/a00ium/p/14128974.html">3. Re:Python的基本Protobuf指南(序列化数据)</a></li>
                <li class="recent_comment_body">@Mos_x 序列化 完成用base64 encode一下, 解序列化的时候decode一下在用ParseFromString函数就可以了...</li>
                <li class="recent_comment_author">--喜又亻</li>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/a00ium/p/14128974.html">4. Re:Python的基本Protobuf指南(序列化数据)</a></li>
                <li class="recent_comment_body">作者您好，我有问题想问一下您， 3.Protobuf对象的序列化章节中，把序列化生成的人类可读的Protobuf消息后，该怎么反序列化呢？ParseFromString函数的话不行，因为它的输入得是二...</li>
                <li class="recent_comment_author">--Mos_x</li>
                <li class="recent_comment_title"><a href="https://www.cnblogs.com/a00ium/p/10360494.html">5. Re:jmeter如何设置全局变量以及调用方法</a></li>
                <li class="recent_comment_body"><p>${__P(newuserid,)}这样就可以了，newuserid后面加上一个英文的逗号，每次全局变量取值都是最新的</p>
</li>
                <li class="recent_comment_author">--上玄月-sunshine</li>
        </ul>
    </div>
</div>

</div>


</div>
                    <script>loadBlogSideColumn();</script>
			</div>			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		<!--done-->
Copyright © 2024 DaisyLinux
<br><span id="poweredby">Powered by .NET 8.0 on Kubernetes</span>



	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->



    

    <input type="hidden" id="antiforgery_token" value="CfDJ8ONv0caE5GtEh3YJ5j088klhJgWif__e5Wr6IvDtQJZFbTEOlVu7l4wjF5e7us-6eXnZpue5nwwJnzjAtNdbRTnROtzFrK311MOPC69gxMLLlkJjZFHHv3Cpe-a1rp07GWFIJhbZSvehYuldwvWuCLE">
    <script async="" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/js"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag() { dataLayer.push(arguments); }
    gtag('js', new Date());
    gtag('config', 'G-M95P3TTWJZ');
</script>
<script defer="" src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/hm.js"></script>


<div style="z-index: 998; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); display: none; flex-direction: column; align-items: center; justify-content: center">
<div style="background: #fff;padding: 30px; margin: 30px; border-radius: 16px;">
  <div style="width: 200px; height: 200px; background: rgba(255, 255, 255, 0.8); position: absolute; top: -100px; right: -100px; border-radius: 100px"></div>
  <div style="text-align: center; font-size: 18px; margin-bottom: 10px;">点击右上角即可分享</div>
  <img src="./Python的基本Protobuf指南(序列化数据) - DaisyLinux - 博客园_files/35695-20230906145857937-1471873834.gif" alt="微信分享提示">
</div>   
    </div></body></html>